package cn.deathgun.dcswebspringboot.controller

import cn.deathgun.dcswebspringboot.service.impl.PlayerServiceImpl
import jakarta.annotation.Resource
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/player")
class DataSystemController (@Resource private val playerService:PlayerServiceImpl){

    @PostMapping("/info/{ucid}")
    fun playerGetInfo(
        @PathVariable ucid:String,
    ): String {
        val player = playerService.getPlayerInfo(ucid)
        return "PlayerName: " + player.name + "\npts: " + player.pts
    }

    @PostMapping("/login")
    fun playerRegister(@RequestParam ucid: String,
                       @RequestParam name: String): String {
        print("ucid$ucid\nname$name")
        val playerInfo = playerService.playerJoinGame(ucid, name)
        return "玩家 ${playerInfo.name}: \n - 分数: ${playerInfo.pts}\n输入 -myinfo 查看更多!"
    }

    @PostMapping("/teamkill")
    fun playerTeamKill(@RequestParam ucid: String):String = playerService.playerUpdate(ucid, 1)

    @PostMapping("/landing")
    fun playerLanding(@RequestParam ucid:String):String = playerService.playerUpdate(ucid, 2)

    @PostMapping("/dead")
    fun playerDead(@RequestParam ucid:String):String = playerService.playerUpdate(ucid, 3)

    @PostMapping("/kill")
    fun playerGetKill(@RequestParam typeName:String,
                      @RequestParam ucid: String):String
    = playerService.playerGetKill(typeName,ucid)

    @PostMapping("/myInfo")
    fun playerGetMyInfo(@RequestParam ucid:String): String {
        val player = playerService.getPlayerInfo(ucid)
        return if (player != null) {
            player.name + "的数据: " +
                    " - pts: " + player.pts.toString() +
                    " - 空战战果: " + player.splashAA.toString() +
                    " - 对地战果: " + player.splashAG.toString() +
                    " - 反辐射战果: " + player.splashSEAD.toString() +
                    " - 反舰战果: " + player.splashSHIP.toString()+
                    " - 阵亡次数: " + player.dead.toString() +
                    " - 回收次数: " + player.landing.toString() +
                    " - 友军误杀次数: " + player.teamkill.toString()
        } else {
            "系统错误，未查到用户信息"
        }

    }

}